package cc.z8g.browser.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

import cc.z8g.browser.R;

/**
 * Dialog 用 ListView 展示
 *
 * @author zhaoxuyang.net
 * @since 2024-08-14
 */
public class DialogItemAdapter extends ArrayAdapter<DialogItem> {

    public DialogItemAdapter(@NonNull final Context context, final int resource, @NonNull final List<DialogItem> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            view = inflater.inflate(R.layout.simple_list_item, parent, false);
        }

        DialogItem item = getItem(position);
        if (item != null) {
            TextView textView = view.findViewById(R.id.title_text);
            textView.setText(getContext().getString(item.getTitle()));
        }

        return view;
    }
}